#include<iostream>

#include<unistd.h>

using namespace std;

void test1(){
  while(1){
cout<<"the PID is  "<<getpid()<<endl;
cout<<"the PPID is  "<<getppid()<<endl;
cout<<"##########################"<<endl;

 sleep(1);
  }
}

//////////////////////////////////////////////

void test2(){
  
  cout<<"it'a test"<<endl;
  fork();
  cout<<"PID:"<<getpid()<<endl;
}

///////////////////////////////////////////// 

void test3(){
  pid_t ret = fork();
  if(ret<0) cerr<<"fork fail"<<endl;
  if(ret==0) while(1){
    cout<<"子进程 ret:"<<ret<<"  PID: "<<getpid()<<"  PPID: "<<getppid()<<endl;
  sleep(1);
  }
  if(ret>0)while(1){
    cout<<"父进程 ret:"<<ret<<"  PID: "<<getpid()<<"  PPID: "<<getppid()<<endl;
  sleep(1);
  }

}

/////////////////////////////////////////////// 

void test4(){
  while(1){
   // cout<<"hello world"<<endl;
  }
}

//////////////////////////////////////////////// 

void test5(){
  int a = 0;
  cin>>a;
}

/////////////////////////////////////////////// 

void test6(){
  sleep(1000);
}

////////////////////////////////////////////// 

void test7(){
  while(1){
    cout<<"test"<<endl;
    
    sleep(1);
  }
}

int main()
{
  //test1();
  
  //test2();
  
  test3();
  
  //test4();
  
  //test5();

  //test6();

  //test7();

  return 0;
}
